<?php

namespace App\Http\Validators\V1;

use App\Constants\CashConstant;
use App\Http\Validators\AbstractValidator;

/*
 *
 * 验证接口
 */

class CashValidator extends AbstractValidator
{

    /**
     * Validation rules
     *
     * @var Array
     */
    // 要验证的字段
    protected $rules = array(
        'number'   => ['required', 'integer','min_money'],
    );

    /**
     * Validation messages
     *
     * @var Array
     */
    //自定义错误信息
    protected $messages = array(
        'number.required' => '提现金额必填',
        'number.integer' => '提现金额必须为整数',
        'number.min_money' => '最低提现额度5元',

    );
    public function before()
    {
        // 自定义规则检查提现金额
        $this->extend('min_money', function ($attribute, $value, $parameters) {
            if (preg_match("/^[1-9]+[0-9]*$/u", $value)) {
                if ($value >= CashConstant::ACCOUNT_CASH) {
                    return true;
                }
            }
            return false;
        });

    }



}
